const waitOn = require('wait-on');
const { spawn } = require('child_process');
const path = require('path');

console.log('Waiting for Vite server to start...');

// 等待Vite开发服务器启动
waitOn({
  resources: ['tcp:3000'],
  timeout: 30000, // 30秒超时
}).then(() => {
  console.log('Vite server is ready, starting Electron...');
  
  // 启动Electron
  const electronProcess = spawn('electron', ['electron-dev.js'], {
    stdio: 'inherit',
    shell: true
  });
  
  electronProcess.on('error', (err) => {
    console.error('Failed to start Electron:', err);
  });
  
  electronProcess.on('close', (code) => {
    console.log(`Electron exited with code ${code}`);
    process.exit(code);
  });
}).catch((err) => {
  console.error('Error waiting for Vite server:', err);
  process.exit(1);
}); 